package com.pa.authorization.controller;

import com.alibaba.fastjson.JSON;
import com.lww.springcloudapi.entity.TabEmployee;
import com.lww.springcloudapi.result.Result;
import com.lww.springcloudapi.result.ResultCodeEnum;
import com.lww.springcloudapi.utils.AuthContextHolder;
import com.pa.authorization.service.TabEmployeeLoginService;
import io.swagger.annotations.Api;
import lombok.val;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.security.Principal;
import java.util.List;

/**
 * <p>
 * 管理员登录 前端控制器
 * </p>
 *
 * @author SHEN
 * @since 2021-03-11
 */
@Api(description = "管理员登录")
@RestController
@RequestMapping("/employee-login")
public class TabEmployeeLoginController {
    @Autowired
    TabEmployeeLoginService tabEmployeeLoginService;

    @GetMapping("/login")
    public Result login(String username, String password) {
        TabEmployee tabEmployee = new TabEmployee();
        tabEmployee.setAccount(username);
        tabEmployee.setPassword(password);

        Result tabEmployee1 = tabEmployeeLoginService.AdministratorLogin(tabEmployee);

        return tabEmployee1;
    }

    @RequestMapping("/info")
    public Result findQuery() {
        Result query = tabEmployeeLoginService.findQuery();
        return query;
    }

    //获取用户id信息接口
    @GetMapping("/getUserInfo")
    public Result getUserInfo(HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        TabEmployee byId = tabEmployeeLoginService.getById(userId);
        return Result.ok(byId);
    }


    @RequestMapping("/getUserNameAll")
    public Result findQueryName() {
        List<String> queryName = tabEmployeeLoginService.findQueryName();
        return Result.ok(queryName);
    }
}
